package com.hubu.parking.model.enums;

import lombok.Getter;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 车位状态枚举
 */
public enum SpotStatusEnum {

    AVAILABLE(0, "available", "可用"),
    RESERVED(1, "reserved", "已预约"),
    PARKED(2, "parked", "已使用"),
    ;

    @Getter
    private final Integer value;

    @Getter
    private final String englishDesc;

    @Getter
    private final String desc;

    SpotStatusEnum(Integer value, String englishDesc, String desc) {
        this.value = value;
        this.englishDesc = englishDesc;
        this.desc = desc;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<Integer> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static SpotStatusEnum getEnumByValue(Integer value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (SpotStatusEnum anEnum : SpotStatusEnum.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }

}
